package com.otomotion.research.ants.core;

import com.otomotion.research.ants.databank.UberRepository;
import com.otomotion.research.ants.entities.Ant;
import com.otomotion.research.ants.util.LOGGER;

import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;


/**
 * @author    joel
 */
public class Engine extends Thread
{
    private Gaia gaia;
    private UberRepository repository;



    Engine(Gaia g, UberRepository ur )
    {
        this.gaia = g;
        this.repository = ur;

    }

    @Override
    public void run()
    {

        while(true)
        {
            Collection<Ant> ants = this.repository.getIdleAnts();
            Iterator i = ants.iterator();
            
            //ANT REPORT
//            LOGGER.log("ANT REPORT");
//            while(i.hasNext())
//            {
//
//                Ant a = (Ant)i.next();
//                LOGGER.log("ANT#"+a.getId()+ "located at: "+a.getLocation().toString());
//
//            }
            
            
            
            i = ants.iterator();
            while(i.hasNext())
            {
            	try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
                gaia.processPhysics();
                gaia.processAnt((Ant)i.next());

            }
        }
    }


}
